package com.cn.wxwinnie.file;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author 潇湘暮雨 E-mail:wxwinnie@hotmail.com
 * 
 * @version 创建时间：2014年3月24日 下午9:03:42
 * 
 */
public class MyFileRead {

	public static void main(String[] args) throws IOException {
		File f = new File("d:/FileRead.txt");
		InputStream is = new FileInputStream(f);
		FileInputStream fis = new FileInputStream(f);
		FileReader fr = new FileReader(f);
		BufferedReader br = new BufferedReader(fr);

		String ss = "";

		List<Byte> temp = new ArrayList<Byte>();
		byte[] b = new byte[10];
		while (-1 != is.read(b)) {
			for (int i = 0; i < b.length; i++) {
				if (b[i] != 0) {
					temp.add(b[i]);
					System.out.print(b[i] + " ");
					b[i] = 0;
				}
			}
		}
		byte[] temps = new byte[temp.size()];
		for (int i = 0; i < temp.size(); i++) {
			temps[i] = temp.get(i);
		}
		System.out.println();
		System.out.println(new String(temps, "utf-8"));
		System.out.println("temp.size() : " + temp.size());

		// //////////////////////////////////////////////////////
		/*
		 * 每次读一行
		 */
		String s = br.readLine();
		String tep = "";
		while (null != (tep = br.readLine())) {
			s += tep;
		}

		System.out.println(s.substring(0, 4));
		System.out.println(s.substring(0, 5));
		System.out.println(s.substring(0, 6));

		System.out.println(s);
		System.out.println("s.length():" + s.length());
		// //////////////////////////////////////////////////////

	}

}
